package org.cying.main.util;

import org.cying.main.domain.*;
import org.cying.main.feign.TaskFeignDept;
import org.cying.main.service.TaskService;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

/**
 * 部门服务属性库
 * @author Cying
 */
public class TaskUtils {

    public static void departmentHandler(List<Task> tasks, Long sid, Integer complete, Student student, TaskFeignDept dSer, TaskService service) {
        Iterator<Task> iterator = tasks.iterator();
        while (iterator.hasNext()) {
            Task task = iterator.next();
            SampleResult<List<Department>> result = dSer.getDepartment(task.getUid());
            List<Department> department = result.getData();
            if (sid != null) {
                CommitContent record = service.getCommited(sid, task.getUid()).combile(student);
                Department _dept = department.get(department.indexOf(new Department(student.getDept())));
                List<Group> group = _dept.getGroupList();
                Group _group = group.get(group.indexOf(new Group(student.getGroup())));
                _group.setStudentList(new ArrayList<>(Collections.singletonList(record)));
                task.setComplete(record.getFlag());
                if (complete != null && complete != record.getFlag())
                    iterator.remove();
            }
            task.setDeptList(department);
        }
    }

}
